package pa165.dominatingspecies.frontend.user;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.springframework.security.access.prepost.PreAuthorize;
import pa165.dominating.species.enums.UserType;
import pa165.dominating.species.service.UserService;
import pa165.dominating.species.tos.UserTO;
import pa165.dominatingspecies.frontend.element.EnumPropertyModel;
import pa165.dominatingspecies.frontend.pages.BasePage;

/**
 * @author Tomas Kalla
 */
@PreAuthorize("hasRole('ADMIN')")
public class UserDetailPage extends BasePage {

    @SpringBean(name = "userService")
    private UserService userService;

    private UserTO userTO;

    UserDetailPage(Long id) {
        if (id != null) {
            userTO = userService.getUserById(id);
        }

        add(new Label("userName", userTO.getName()));
        add(new Label("userLogin", userTO.getLogin()));
        add(new Label("userType", new EnumPropertyModel<UserType>(userTO, "type", this)));


        add(new UserPageLink("backToList"));
        add(new EditUserLink("edit", userTO.getId()));

    }

}
